package com.mashibing.controller;


import com.mashibing.internalcommon.dto.OrderInfo;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.DriverGrabRequest;
import com.mashibing.internalcommon.request.OrderRequest;
import com.mashibing.service.GrabService;
import com.mashibing.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 孟瑞达
 * @since 2025-06-26
 */
@RestController
@RequestMapping("/order")
public class OrderInfoController {

    @Autowired
    private OrderService orderService;

    @Autowired
    @Qualifier("grabByRedissonBasicService")
//    @Qualifier("GrabByZookeeperCuratorService")
    private GrabService grabService;

    @PostMapping("/add")
    public ResponseResult addOrder(@RequestBody OrderRequest orderRequest) {
        return orderService.addOrder(orderRequest);
    }

    @PostMapping("/book")
    public ResponseResult book(@RequestBody OrderRequest orderRequest) {
        return orderService.book(orderRequest);
    }

    /**
     * 司机抢单
     * @param driverGrabRequest
     * @return
     */
    @PostMapping("/grab")
    public ResponseResult driverGrab(@RequestBody DriverGrabRequest driverGrabRequest){
        return grabService.grab(driverGrabRequest);
    }

    /**
     * 去接乘客
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody OrderRequest orderRequest) {
        return orderService.toPickUpPassenger(orderRequest);
    }

    /**
     * 到达乘客上车点
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/arrivedDeparture")
    public ResponseResult arrivedDeparture(@RequestBody OrderRequest orderRequest) {
        return orderService.arrivedDeparture(orderRequest);
    }

    /**
     * 司机接到乘客
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/pickUpPassenger")
    public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest) {
        return orderService.pickUpPassenger(orderRequest);
    }

    /**
     * 乘客到达目的地，行程终止
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/passengerGetOff")
    public ResponseResult passengerGetOff(@RequestBody OrderRequest orderRequest) {
        return orderService.passengerGetOff(orderRequest);
    }


    /**
     * 司机发起收款
     * @param orderRequest
     * @return
     */
    @PostMapping("/pushPayInfo")
    public ResponseResult pushPayInfo(@RequestBody OrderRequest orderRequest){
        return orderService.pushPayInfo(orderRequest);
    }

    /**
     * 支付完成
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/pay")
    public ResponseResult pay(@RequestBody OrderRequest orderRequest) {
        return orderService.pay(orderRequest);
    }

    /**
     * 订单取消
     *
     * @param orderId
     * @param identity
     * @return
     */
    @PostMapping("/cancel")
    public ResponseResult cancel(Long orderId, String identity) {
        return orderService.cancel(orderId, identity);
    }


    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(Long orderId){
        return orderService.detail(orderId);
    }
}
